package com.HuangJiaQing.www.controller;


import com.HuangJiaQing.www.model.Goods;
import com.HuangJiaQing.www.model.Marketers;
import com.HuangJiaQing.www.service.MarketersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @author HONOR
 * @date 2022/7/29 15:12
 */
@Controller
public class MarketersController {
    @Autowired
    private MarketersService marketersService;

    @RequestMapping(value = "/toRegistMarketers",method = RequestMethod.GET)
    public String toRegisterMarketers(){
        return "registMarketers";
    }

    @RequestMapping(value = "/registMarketers",method = RequestMethod.POST)
    public String registerMarketers(Marketers marketers){
        boolean b = marketersService.registerMarketers(marketers);
        if (b){
            return "login";
        }else {
            return "registMarketers";
        }
    }

    @RequestMapping(value = "/forbidMarketers/{id}",method = RequestMethod.PUT)
    public String updateMarketersForbid(@PathVariable("id") Integer id){
        marketersService.updateMarketersForbidById(id);
        return "redirect:/adminLogin";
    }

    @RequestMapping(value = "/unsealMarketers/{id}",method = RequestMethod.PUT)
    public String updateMarketersUnseal(@PathVariable("id") Integer id){
        marketersService.updateMarketersUnsealById(id);
        return "redirect:/adminLogin";
    }

    @RequestMapping("/marketersLogin")
    public String marketersLogin(Model model){
        List<Goods> goods = marketersService.marketersLogin();
        model.addAttribute("goods",goods);
        return "marketers";
    }
}
